<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::HMAC - openssl: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-OpenSSL::HMAC-label-HMAC-SHA256+using+one-shot+interface">HMAC-SHA256 using one-shot interface</a>
    <li><a href="#class-OpenSSL::HMAC-label-HMAC-SHA256+using+incremental+interface">HMAC-SHA256 using incremental interface</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-base64digest">::base64digest</a>
    <li ><a href="#method-c-digest">::digest</a>
    <li ><a href="#method-c-hexdigest">::hexdigest</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-base64digest">#base64digest</a>
    <li ><a href="#method-i-digest">#digest</a>
    <li ><a href="#method-i-hexdigest">#hexdigest</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-reset">#reset</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-update">#update</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::HMAC">
    <h1 id="class-OpenSSL::HMAC" class="class">
      class OpenSSL::HMAC
    </h1>

    <section class="description">
    
<p><a href="HMAC.html"><code>OpenSSL::HMAC</code></a> allows computing Hash-based Message Authentication Code (<a href="HMAC.html"><code>HMAC</code></a>). It is a type of message authentication code (MAC) involving a hash function in combination with a key. <a href="HMAC.html"><code>HMAC</code></a> can be used to verify the integrity of a message as well as the authenticity.</p>

<p><a href="HMAC.html"><code>OpenSSL::HMAC</code></a> has a similar interface to <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="class-OpenSSL::HMAC-label-HMAC-SHA256+using+one-shot+interface">HMAC-SHA256 using one-shot interface<span><a href="#class-OpenSSL::HMAC-label-HMAC-SHA256+using+one-shot+interface">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&quot;key&quot;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&quot;message-to-be-authenticated&quot;</span>
<span class="ruby-identifier">mac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-string">&quot;SHA256&quot;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e&quot;</span>
</pre>

<h3 id="class-OpenSSL::HMAC-label-HMAC-SHA256+using+incremental+interface">HMAC-SHA256 using incremental interface<span><a href="#class-OpenSSL::HMAC-label-HMAC-SHA256+using+incremental+interface">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">data1</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">binread</span>(<span class="ruby-string">&quot;file1&quot;</span>)
<span class="ruby-identifier">data2</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">binread</span>(<span class="ruby-string">&quot;file2&quot;</span>)
<span class="ruby-identifier">key</span> = <span class="ruby-string">&quot;key&quot;</span>
<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-string">&#39;SHA256&#39;</span>)
<span class="ruby-identifier">hmac</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data1</span>
<span class="ruby-identifier">hmac</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data2</span>
<span class="ruby-identifier">mac</span> = <span class="ruby-identifier">hmac</span>.<span class="ruby-identifier">digest</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-base64digest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          base64digest(digest, key, data) &rarr; aString
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code as a Base64-encoded string. The <em>digest</em> parameter specifies the digest algorithm to use. This may be a String representing the algorithm name or an instance of <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="method-c-base64digest-label-Example">Example<span><a href="#method-c-base64digest-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;The quick brown fox jumps over the lazy dog&#39;</span>

<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">base64digest</span>(<span class="ruby-string">&#39;SHA1&#39;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;3nybhbi3iqa8ino29wqQcBydtNk=&quot;</span>
</pre>

                              <div class="method-source-code" id="base64digest-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/hmac.rb, line 73</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">base64digest</span>(<span class="ruby-identifier">digest</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
  [<span class="ruby-identifier">digest</span>(<span class="ruby-identifier">digest</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)].<span class="ruby-identifier">pack</span>(<span class="ruby-string">&quot;m0&quot;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-digest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          digest(digest, key, data) &rarr; aString
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code as a binary string. The <em>digest</em> parameter specifies the digest algorithm to use. This may be a String representing the algorithm name or an instance of <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="method-c-digest-label-Example">Example<span><a href="#method-c-digest-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;The quick brown fox jumps over the lazy dog&#39;</span>

<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">digest</span>(<span class="ruby-string">&#39;SHA1&#39;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;\xDE|\x9B\x85\xB8\xB7\x8A\xA6\xBC\x8Az6\xF7\n\x90p\x1C\x9D\xB4\xD9&quot;</span>
</pre>

                              <div class="method-source-code" id="digest-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/hmac.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">digest</span>(<span class="ruby-identifier">digest</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
  <span class="ruby-identifier">hmac</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">digest</span>)
  <span class="ruby-identifier">hmac</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data</span>
  <span class="ruby-identifier">hmac</span>.<span class="ruby-identifier">digest</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-hexdigest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hexdigest(digest, key, data) &rarr; aString
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code as a hex-encoded string. The <em>digest</em> parameter specifies the digest algorithm to use. This may be a String representing the algorithm name or an instance of <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="method-c-hexdigest-label-Example">Example<span><a href="#method-c-hexdigest-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;The quick brown fox jumps over the lazy dog&#39;</span>

<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-string">&#39;SHA1&#39;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9&quot;</span>
</pre>

                              <div class="method-source-code" id="hexdigest-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/hmac.rb, line 54</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hexdigest</span>(<span class="ruby-identifier">digest</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
  <span class="ruby-identifier">hmac</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">digest</span>)
  <span class="ruby-identifier">hmac</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data</span>
  <span class="ruby-identifier">hmac</span>.<span class="ruby-identifier">hexdigest</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(key, digest) &rarr; hmac
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an instance of <a href="HMAC.html"><code>OpenSSL::HMAC</code></a> set with the key and digest algorithm to be used. The instance represents the initial state of the message authentication code before any data has been processed. To process data with it, use the instance method <a href="HMAC.html#method-i-update"><code>update</code></a> with your data as an argument.</p>

<h3 id="method-c-new-label-Example">Example<span><a href="#method-c-new-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">instance</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-string">&#39;SHA1&#39;</span>)
<span class="ruby-comment">#=&gt; f42bb0eeb018ebbd4597ae7213711ec60760843f</span>
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">class</span>
<span class="ruby-comment">#=&gt; OpenSSL::HMAC</span>
</pre>

<h3 id="method-c-new-label-A+note+about+comparisons">A note about comparisons<span><a href="#method-c-new-label-A+note+about+comparisons">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Two instances can be securely compared with <a href="HMAC.html#method-i-3D-3D"><code>==</code></a> in constant time:</p>

<pre class="ruby">    <span class="ruby-identifier">other_instance</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;key&#39;</span>, <span class="ruby-string">&#39;SHA1&#39;</span>)
<span class="ruby-comment">#=&gt; f42bb0eeb018ebbd4597ae7213711ec60760843f</span>
<span class="ruby-identifier">instance</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other_instance</span>
<span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
{
    EVP_MD_CTX *ctx;
    EVP_PKEY *pkey;

    GetHMAC(self, ctx);
    StringValue(key);
#ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
    pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL,
                                        (unsigned char *)RSTRING_PTR(key),
                                        RSTRING_LENINT(key));
    if (!pkey)
        ossl_raise(eHMACError, &quot;EVP_PKEY_new_raw_private_key&quot;);
#else
    pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
                                (unsigned char *)RSTRING_PTR(key),
                                RSTRING_LENINT(key));
    if (!pkey)
        ossl_raise(eHMACError, &quot;EVP_PKEY_new_mac_key&quot;);
#endif
    if (EVP_DigestSignInit(ctx, NULL, ossl_evp_get_digestbyname(digest),
                           NULL, pkey) != 1) {
        EVP_PKEY_free(pkey);
        ossl_raise(eHMACError, &quot;EVP_DigestSignInit&quot;);
    }
    /* Decrement reference counter; EVP_MD_CTX still keeps it */
    EVP_PKEY_free(pkey);

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3C" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">&lt;&lt;</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <em>hmac</em> updated with the message to be authenticated. Can be called repeatedly with chunks of the message.</p>

<h3 id="method-i-3C-3C-label-Example">Example<span><a href="#method-i-3C-3C-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">first_chunk</span> = <span class="ruby-string">&#39;The quick brown fox jumps &#39;</span>
<span class="ruby-identifier">second_chunk</span> = <span class="ruby-string">&#39;over the lazy dog&#39;</span>

<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">first_chunk</span>)
<span class="ruby-comment">#=&gt; 5b9a8038a65d571076d97fe783989e52278a492a</span>
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">second_chunk</span>)
<span class="ruby-comment">#=&gt; de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HMAC.html#method-i-update">update</a>
                            </div>
                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">==</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Securely compare with another <a href="HMAC.html"><code>HMAC</code></a> instance in constant time.</p>

                              <div class="method-source-code" id="3D-3D-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/hmac.rb, line 6</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">==</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">HMAC</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">digest</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">digest</span>.<span class="ruby-identifier">bytesize</span>

  <span class="ruby-constant">OpenSSL</span>.<span class="ruby-identifier">fixed_length_secure_compare</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">digest</span>, <span class="ruby-identifier">other</span>.<span class="ruby-identifier">digest</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-base64digest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          base64digest &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code an a Base64-encoded string.</p>

                              <div class="method-source-code" id="base64digest-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/hmac.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">base64digest</span>
  [<span class="ruby-identifier">digest</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-string">&quot;m0&quot;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-digest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          digest &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code an instance represents as a binary string.</p>

<h3 id="method-i-digest-label-Example">Example<span><a href="#method-i-digest-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">instance</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;key&#39;</span>, <span class="ruby-string">&#39;SHA1&#39;</span>)
<span class="ruby-comment">#=&gt; f42bb0eeb018ebbd4597ae7213711ec60760843f</span>
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">digest</span>
<span class="ruby-comment">#=&gt; &quot;\xF4+\xB0\xEE\xB0\x18\xEB\xBDE\x97\xAEr\x13q\x1E\xC6\a`\x84?&quot;</span>
</pre>

                              <div class="method-source-code" id="digest-source">
            <pre>static VALUE
ossl_hmac_digest(VALUE self)
{
    EVP_MD_CTX *ctx;
    size_t buf_len = EVP_MAX_MD_SIZE;
    VALUE ret;

    GetHMAC(self, ctx);
    ret = rb_str_new(NULL, EVP_MAX_MD_SIZE);
    if (EVP_DigestSignFinal(ctx, (unsigned char *)RSTRING_PTR(ret),
                            &amp;buf_len) != 1)
        ossl_raise(eHMACError, &quot;EVP_DigestSignFinal&quot;);
    rb_str_set_len(ret, (long)buf_len);

    return ret;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hexdigest" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hexdigest &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code an instance represents as a hex-encoded string.</p>

                              <div class="method-source-code" id="hexdigest-source">
            <pre>static VALUE
ossl_hmac_hexdigest(VALUE self)
{
    EVP_MD_CTX *ctx;
    unsigned char buf[EVP_MAX_MD_SIZE];
    size_t buf_len = EVP_MAX_MD_SIZE;
    VALUE ret;

    GetHMAC(self, ctx);
    if (EVP_DigestSignFinal(ctx, buf, &amp;buf_len) != 1)
        ossl_raise(eHMACError, &quot;EVP_DigestSignFinal&quot;);
    ret = rb_str_new(NULL, buf_len * 2);
    ossl_bin2hex(buf, RSTRING_PTR(ret), buf_len);

    return ret;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HMAC.html#method-i-inspect">inspect</a>, <a href="HMAC.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-initialize_copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">initialize_copy</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
ossl_hmac_copy(VALUE self, VALUE other)
{
    EVP_MD_CTX *ctx1, *ctx2;

    rb_check_frozen(self);
    if (self == other) return self;

    GetHMAC(self, ctx1);
    GetHMAC(other, ctx2);
    if (EVP_MD_CTX_copy(ctx1, ctx2) != 1)
        ossl_raise(eHMACError, &quot;EVP_MD_CTX_copy&quot;);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code as a hex-encoded string. The <em>digest</em> parameter specifies the digest algorithm to use. This may be a String representing the algorithm name or an instance of <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="method-i-inspect-label-Example">Example<span><a href="#method-i-inspect-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;The quick brown fox jumps over the lazy dog&#39;</span>

<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-string">&#39;SHA1&#39;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9&quot;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HMAC.html#method-i-hexdigest">hexdigest</a>
                            </div>
                          </div>

                  <div id="method-i-reset" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          reset &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <em>hmac</em> as it was when it was first initialized, with all processed data cleared from it.</p>

<h3 id="method-i-reset-label-Example">Example<span><a href="#method-i-reset-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&quot;The quick brown fox jumps over the lazy dog&quot;</span>
<span class="ruby-identifier">instance</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;key&#39;</span>, <span class="ruby-string">&#39;SHA1&#39;</span>)
<span class="ruby-comment">#=&gt; f42bb0eeb018ebbd4597ae7213711ec60760843f</span>

<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9</span>
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">reset</span>
<span class="ruby-comment">#=&gt; f42bb0eeb018ebbd4597ae7213711ec60760843f</span>
</pre>

                              <div class="method-source-code" id="reset-source">
            <pre>static VALUE
ossl_hmac_reset(VALUE self)
{
    EVP_MD_CTX *ctx;
    EVP_PKEY *pkey;

    GetHMAC(self, ctx);
    pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_get_pkey_ctx(ctx));
    if (EVP_DigestSignInit(ctx, NULL, EVP_MD_CTX_get0_md(ctx), NULL, pkey) != 1)
        ossl_raise(eHMACError, &quot;EVP_DigestSignInit&quot;);

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the authentication code as a hex-encoded string. The <em>digest</em> parameter specifies the digest algorithm to use. This may be a String representing the algorithm name or an instance of <a href="Digest.html"><code>OpenSSL::Digest</code></a>.</p>

<h3 id="method-i-to_s-label-Example">Example<span><a href="#method-i-to_s-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">key</span> = <span class="ruby-string">&#39;key&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;The quick brown fox jumps over the lazy dog&#39;</span>

<span class="ruby-identifier">hmac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-string">&#39;SHA1&#39;</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-comment">#=&gt; &quot;de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9&quot;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HMAC.html#method-i-hexdigest">hexdigest</a>
                            </div>
                          </div>

                  <div id="method-i-update" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          update(string) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <em>hmac</em> updated with the message to be authenticated. Can be called repeatedly with chunks of the message.</p>

<h3 id="method-i-update-label-Example">Example<span><a href="#method-i-update-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">first_chunk</span> = <span class="ruby-string">&#39;The quick brown fox jumps &#39;</span>
<span class="ruby-identifier">second_chunk</span> = <span class="ruby-string">&#39;over the lazy dog&#39;</span>

<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">first_chunk</span>)
<span class="ruby-comment">#=&gt; 5b9a8038a65d571076d97fe783989e52278a492a</span>
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">second_chunk</span>)
<span class="ruby-comment">#=&gt; de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9</span>
</pre>

                              <div class="method-source-code" id="update-source">
            <pre>static VALUE
ossl_hmac_update(VALUE self, VALUE data)
{
    EVP_MD_CTX *ctx;

    StringValue(data);
    GetHMAC(self, ctx);
    if (EVP_DigestSignUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data)) != 1)
        ossl_raise(eHMACError, &quot;EVP_DigestSignUpdate&quot;);

    return self;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HMAC.html#method-i-3C-3C">&lt;&lt;</a>
                            </div>

                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

